﻿@model ActionTrackerEntities.ParamMetricaPromedio
@{
    ViewBag.Title = "Métrica Promedio | Action Tracker";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section script
{
     <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>  
    <script type="text/javascript">
        $(document).ready(function () {
            $("#ddlAnio").hide();
            $("#ddlMes").hide();

            $('#IdTipoMetrica').change(function () {
                var seleccionado = $('#IdTipoMetrica :selected').val();
                
                if (seleccionado != "") {
                    
                    switch (seleccionado) {
                        case "1":
                            //console.log("el 1!");
                            $("#ddlAnio").show();
                            $("#ddlMes").hide();
                            $("#IdMes :selected").val("");
                            $("#IdAnio :selected").val("");
                            break;
                        case "2":
                            //console.log("el 2!");
                            $("#ddlAnio").hide();
                            $("#ddlMes").show();
                            $("#IdMes :selected").val("");
                            $("#IdAnio :selected").val("");
                            break;
                        case "3":
                            //console.log("default!");
                            $("#IdMes :selected").val("1");
                            $("#IdAnio :selected").val("1");
                            $("#ddlAnio").hide();
                            $("#ddlMes").hide();
                            break;
                    }
                } else {
                    $("#ddlAnio").hide();
                    $("#ddlMes").hide();
                    $("#IdMes :selected").val("");
                    $("#IdAnio :selected").val("");
                }
                
            });

            $("#IdAnio").change(function () {
                if ($("IdAnio :selected").val() != "") {
                    $("#IdMes :selected").val("1");
                } else {
                    $("#IdMes :selected").val("");
                }
            });
            $("#IdMes").change(function () {
                if ($("IdMes :selected").val() != "") {
                    $("#IdAnio :selected").val("1");
                } else {
                    $("#IdAnio :selected").val("");
                }
            });
        });
    </script>

}
@using (Html.BeginForm("EmitirMetricaPromedio", "Accion", FormMethod.Post))
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Métrica promedio</legend>
        <div class="control-group">
            @Html.LabelFor(model => model.IdTipoMetrica)
            <div class="controls" id="tipoMetricaPromedio">
                @Html.DropDownListFor(model => model.IdTipoMetrica, (SelectList)ViewData["TipoMetricaPromedio"], "(Seleccione)")
                @Html.ValidationMessageFor(model => model.IdTipoMetrica)
            </div>
        </div>
        
        <div class="control-group" id="ddlAnio">
            @Html.LabelFor(model => model.IdAnio)
            <div class="controls" >
                @Html.DropDownListFor(model => model.IdAnio, new SelectList((Dictionary<int, string>)ViewData["Anios"],"Key","Value"), "(Seleccione)")
                @Html.ValidationMessageFor(model => model.IdAnio)
            </div>
        </div>
        
        <div class="control-group" id="ddlMes">
            @Html.LabelFor(model => model.IdMes)
            <div class="controls">
                @Html.DropDownListFor(model => model.IdMes, new SelectList((Dictionary<int, string>)ViewData["Meses"], "Key", "Value"), "(Seleccione)")
                @Html.ValidationMessageFor(model => model.IdMes)
            </div>
        </div>
        
        <p>
            <input type="submit" value="Emitir" class="btn btn-primary" />
        </p>
    </fieldset>
}
<div>
    @Html.ActionLink("Volver", "Index")
</div>
